-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #5135: adding an edit method to each model object #5138
Conversation
Kudos, SonarCloud Quality Gate passed! |
Took another pass at this and it won't quite line up with what's in sundrio. The initial commit is referencing io.sundr.builder.Editable, and generates / builds just fine. However our generated sundrio logic will actually reference io.fabric8.kubernetes.api.builder.Editable. If I try to reference io.fabric8.kubernetes.api.builder.Editable in the jsonschema2pojo that results in an NPE. One option is to leave this decoupled from sundrio and not implement the interface. Users would still do: pod.toBuilder().... rather than new PodBuilder(pod)... but the dependent builder logic would not find these methods and would still use reflection if needed. Another option is to somehow move the io.fabric8.kubernetes.api.builder classes into kubernetes-model-common. |
f26f286
to
5c6e460
Compare
Updated the pr with what that would look like. A dummy class is used to trigger the builder package inclusion in the common module - the class and generated output are removed from the jar. What's not shown is that the core model needs regenerated to flip the generateBuilderPackage value to false. In total we're marking the class as Editable and adding an edit method with an alias of toBuilder. Obviously the toBuilder method could be handled upstream as a default on the interface. @manusa @iocanel @rohanKanojia @metacosm does this messiness seem worth it? |
I'll see if I can resolve then NPE this upstream in sundrio before moving forward with this hack based approach. |
Opened sundrio/sundrio#396 but could not see how to immediately resolve it. We'll probably need to use this workaround if we want to make the pojos editable any time soon. |
Some thoughts: On
|
The first check in builderOf is for if the item is Editable.
That is in this pr - a dummy class is used to trigger the creation of the fabric8 builder package in a different class.
If you are open to it upstream, then toBuilder could be added as a default method. From a end user perspective it's still a little awkward as an interface (we talked about this a little on a sundrio issue) - as there's currently no additional bounds, you'll need to at least cast to VisitableBuilder. |
SonarCloud Quality Gate failed. 0 Bugs 0.0% Coverage The version of Java (11.0.20.1) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17. Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK to me.
Description
In scope of #5135
This will enable users / us to do something like pod.edit().build() as a clone operation.
I've also opened sundrio/sundrio#376 so that we can align to the common BaseFluent.builderOf method for obtaining a builder. Or in the interim we may need to keep our similar logic and just update it some more and make it static. From there we'll use that in ResourceHandlerImpl and in Serialization (for cloning).
Type of change
test, version modification, documentation, etc.)
Checklist